package crypto.process;

import crypto.util.RandomCrypto;

/**
 * DOCUMENT ME!
 *
 * @author gato
 */
public class Alternate {
  private int divisor = 0;

  /**
   * DOCUMENT ME!
   *
   * @param text DOCUMENT ME!
   *
   * @return DOCUMENT ME!
   */
  public String distribution(String text) {
    divisor = this.calculateDivisor(text);

    char[] arrayText = text.toCharArray();

    char[] arText2   = new char[arrayText.length];

    int    q         = 0;
    int    w         = arrayText.length - 1;

    for (int i = 0; i < arrayText.length; i++) {
      arText2[q] = arrayText[i];
      q++;
      i++;
      arText2[w] = arrayText[i];
      w--;
      i++;
    }

    return new String(arText2);
  }

  private int calculateDivisor(String text) {
    int cantCharacters = text.length();

    int div            = RandomCrypto.getRandomInt(cantCharacters);

    if ((div % 2) == 0) {
      return div;
    } else {
      return this.calculateDivisor(text);
    }
  }
}
